package org.jflame.auth.session;

import java.io.Serializable;

import org.apache.commons.lang3.Validate;

public class SessionInfo implements Serializable {

    private static final long serialVersionUID = -774879621620952576L;

    private long lastRequest;
    private final String principal;
    private final String sessionId;
    private boolean expired = false;

    public SessionInfo(String principal, String sessionId, long lastRequest) {
        Validate.notNull(principal, "Principal required");
        Validate.notEmpty(sessionId, "SessionId required");
        Validate.notNull(lastRequest, "LastRequest required");
        this.principal = principal;
        this.sessionId = sessionId;
        this.lastRequest = lastRequest;
    }

    public void expireNow() {
        this.expired = true;
    }

    public long getLastRequest() {
        return this.lastRequest;
    }

    public String getPrincipal() {
        return this.principal;
    }

    public String getSessionId() {
        return this.sessionId;
    }

    public boolean isExpired() {
        return this.expired;
    }

    public void refreshLastRequest() {
        this.lastRequest = System.currentTimeMillis();
    }
}
